<?php
namespace Swiftx\Bundle\WeChat\System;
use Swiftx\Component\Httpd\Kernel;
use Swiftx\Bundle;
use Swiftx\Interfaces\Orm\Manager;
use Swiftx\Interfaces\Router\Collection;


class Application extends Kernel {

    /**
     * 项目初始化
     */
    public function init(){
        // 注册Bundle模块
        $this->registerBundle($this->fetch(Bundle\WeChat\System\Bundle::class));
    }

    /**
     * 项目引导启动
     */
    public function boot(){
        parent::boot();
        // 项目路由配置
        $router_config = $this->server->parsePath('config/router.ini');
        $router_config = parse_ini_file($router_config, true);
        /** @var Collection $router */
        $router = $this->fetch(Collection::class);
        foreach($router_config as $class_name => $item){
            foreach($item as $key => $value){
                $key = explode('.', $key);
                $dispatcher = $router->getDispatcher($class_name, $key[0]);
                $method = 'set'.ucfirst($key[1]);
                call_user_func([$dispatcher, $method], $value);
            }
        }
    }

}